#include <bits/stdc++.h>
#define int long long
#define PII pair<int, int>
#define db long double
#define ull unsigned long long
#define uint unsigned int
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sec second
#define fi frist
using namespace std;

const int MOD = 998244353, N = 100050;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int T = 1;

inline void read(int &x) {
    int f = 1; x = 0;
    char c = getchar();
    if (c == '-') f = -1;
    while (c > '9' || c < '0') {
        c = getchar();
        if (c == '-') f = -1;
    }
    while (c <= '9' && c >= '0') 
        x = x * 10 + (c - '0'), c = getchar();
    x *= f;
    return;
}

int n, m, L, V, p[N], d[N], v[N], a[N], f4;
struct Line{
    int l, r;
    bool operator<(const Line a) {return l < a.l;}
};
vector<Line> li;
void solve1() {
    int maxn = -1, sum = 0;
    for (int i = 1; i <= m; i++) maxn = max(maxn, p[i]);
    for (int i = 1; i <= n; i++)
        if (v[i] > V && maxn >= d[i]) sum++;
    cout << sum << " " << m - (sum ? 1 : 0) << endl;
}
void solve2() {
    int maxn = -1, sum = 0;
    for (int i = 1; i <= m; i++) maxn = max(maxn, p[i]);
    for (auto i : li)
        if (i.l <= maxn) sum++;
    cout << sum << " " << m - (sum ? 1 : 0) << endl;
}
void solve3() {
    // for (int i )
}
signed main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> T;
    while (T--) {
        li.clear();
        int f1 = 1, f2 = 1, f3 = 1, sum = 0;
        cin >> n >> m >> L >> V;
        for (int i = 1, l, r; i <= n; i++) {
            cin >> d[i] >> v[i] >> a[i];
            if (a[i] < 0) {
                if (v[i] <= V) continue;
                l = d[i], r = d[i] + min((int)ceil(double(V * V - v[i] * v[i]) / double(a[i] * 2)) - 1, L);
                li.push_back({l, r});
            }
            if (a[i] > 0) {
                l = d[i] + floor(double(V * V - v[i] * v[i]) / double(a[i] * 2) + 1);
                if (l > L) continue;
                r = L;
                li.push_back({l, r});
            }
            if (a[i] == 0 && v[i] > V) {
                li.push_back({d[i], L});
            }
            if (a[i] != 0) f1 = 0;
            if (a[i] < 0) f2 = 0;
        }
        for (int i = 1; i <= m; i++) cin >> p[i];
        if (f1) solve1();
        else if (f2) solve2();
        else solve3();
    }
    return 0;
}
/*
g++ detect.cpp -o detect -O2
1
5 5 15 3
0 3 0
12 4 0
1 1 4
5 5 ‐2
6 4 ‐4
2 5 8 9 15
*/